package com.tengju.bff.interfaces.manage.crm.user;

import com.tengju.bff.interfaces.manage.crm.staff.sentiment.facade.StaffSentimentFacade;
import com.tengju.user.application.sentiment.dto.AddSentimentRecordForm;
import com.tengju.user.application.sentiment.dto.DeleteSentimentForm;
import com.tengju.bff.interfaces.manage.crm.staff.sentiment.form.StaffSentimentRecordListQuery;
import com.tengju.user.application.sentiment.dto.UpdateSentimentRecordForm;
import com.tengju.bff.interfaces.manage.crm.user.facade.SentimentManageFacade;
import com.tengju.bff.interfaces.shared.ApiResponse;
import com.tengju.bff.interfaces.shared.FormVO;
import com.tengju.bff.interfaces.shared.TableVO;
import com.tengju.bff.interfaces.shared.servlet.ManageEntrance;
import com.tengju.bff.interfaces.shared.servlet.ManageUtil;
import com.tengju.support.domain.annotation.BizLog;
import com.tengju.support.domain.annotation.BizLogSysName;
import com.tengju.user.application.sentiment.SentimentManageService;
import com.tengju.user.domain.model.user.Staff;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;


@Validated
@RestController
@Api(tags = "客情后台管理")
@RequestMapping(value = "manage/crm/sentiment")
@Slf4j
@ManageEntrance
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class SentimentManageController {

    private final SentimentManageFacade sentimentManageFacade;
    private final StaffSentimentFacade staffSentimentFacade;
    private final SentimentManageService sentimentManageService;



    @ApiOperation(value = "查询部门人员客情记录信息列表", notes = "查询部门人员客情记录信息列表")
    @RequestMapping(value = "querySentimentByPage", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<TableVO> querySentimentRecordByPage(@Validated StaffSentimentRecordListQuery query) {
        return ApiResponse.newSuccess(sentimentManageFacade.querySentimentRecordByPage(query));
    }

    @BizLog(sysName = BizLogSysName.TENGJU_CRM)
    @ApiOperation(value = "添加部门人员客情记录信息记录", notes = "添加部门人员客情记录信息记录")
    @RequestMapping(value = "addSentimentRecord", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<Boolean> addSentimentRecord(@Valid @RequestBody AddSentimentRecordForm form) {
        Staff staff = ManageUtil.getOperateUser();
        return ApiResponse.newSuccess(sentimentManageService.addSentimentRecord(form, staff));
    }

    @BizLog(sysName = BizLogSysName.TENGJU_CRM)
    @ApiOperation(value = "删除部门人员客情记录信息列表", notes = "删除部门人员客情记录信息列表")
    @RequestMapping(value = "deleteSentimentRecord", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<Boolean> deleteSentimentRecord(@Valid @RequestBody DeleteSentimentForm form) {
        Staff staff = ManageUtil.getOperateUser();
        return ApiResponse.newSuccess(sentimentManageService.deleteSentimentRecord(form, staff));
    }


    @BizLog(sysName = BizLogSysName.TENGJU_CRM)
    @ApiOperation(value = "修改部门人员客情记录信息列表", notes = "修改部门人员客情记录信息列表")
    @RequestMapping(value = "updateSentimentRecord", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<Boolean> updateSentimentRecord(@Valid @RequestBody UpdateSentimentRecordForm form) {
        Staff staff = ManageUtil.getOperateUser();
        return ApiResponse.newSuccess(sentimentManageService.updateSentimentRecord(form, staff));
    }

    @ApiOperation(value = "获取客情记录服务商查询的添加默认模版", notes = "获取客情记录服务商查询页面添加默认模版")
    @RequestMapping(value = "getDefaultSentimentForm", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<FormVO> getDefaultSentimentForm() {
        return ApiResponse.newSuccess(staffSentimentFacade.getSentimentRecordDefaultForm());
    }


    @ApiOperation(value = "查看部门人员客情记录信息详情", notes = "查看部门人员客情记录信息详情")
    @RequestMapping(value = "getSentimentRecordDetail", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<FormVO> getSentimentRecordDetail(@NotNull(message = "sentimentId不能为空") @RequestParam Long sentimentId) {
        return ApiResponse.newSuccess(staffSentimentFacade.getSentimentRecordDetail(sentimentId));
    }


}
